package com.project;

import com.project.servlet.FindAllServlet;
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.Wrapper;
import org.apache.catalina.startup.Tomcat;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class MainServer {
    private ApplicationContext springContext = new AnnotationConfigApplicationContext(MyBatisConfig.class);

    public MainServer(){
        Tomcat tomcat = new Tomcat();
        tomcat.setPort(8088);
        tomcat.getConnector();

        Context context = tomcat.addContext("", null);
        try {
            Wrapper servlet = Tomcat.addServlet(context, "findAll", springContext.getBean(FindAllServlet.class));
            servlet.setLoadOnStartup(0);
            servlet.addMapping("/findAll");

            tomcat.start();
        } catch (LifecycleException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        new MainServer();
    }
}
